<template>
	<view class="container">
		<view  v-if="list.length!=0" class="tui-coupon-list">

			<view class="tui-coupon-item tui-top20" v-for="item in list" :key="item.id">
				<image  src="/static/img/bg_coupon_3x.png" class="tui-coupon-bg" mode="widthFix"></image>
				<image v-if="index==0" src="/static/img/img_couponcentre_received_3x.png" class="tui-coupon-sign" ></image> 
				<image v-else-if="index==1" src="/static/img/img_coupon_beused_3x.png" class="tui-coupon-sign" ></image> 
				<image  v-else-if="index==2"  src="/static/img/img_coupon_failure_3x.png" class="tui-coupon-sign" ></image> 
				<view class="tui-coupon-item-left">
					<view class="tui-coupon-price-box" >
						<view class="tui-coupon-price-sign" >￥</view>
						<view class="tui-coupon-price tui-price-small">{{item.amount}}</view>
						<!-- <view class="tui-coupon-price-sign" v-if="index%2==0">￥</view> -->
						<!--tui-price-small 面值>4位数的时候为true-->
						<!-- <view class="tui-coupon-price" :class="{'tui-price-small':false}">{{index%2==0?100*(index+1):9}}</view>
						<view class="tui-coupon-price-sign" v-if="index%2!=0">折</view> -->
					</view>
					<view class="tui-coupon-intro">满{{item.minPoint}}元可用</view>
				</view>
				<view class="tui-coupon-item-right">
					<view class="tui-coupon-content">
						<view class="tui-coupon-title-box">
							<view class="tui-coupon-btn" >{{item.useType==0?"全场券":item.useType==1?"分类卷":item.useType==2?"商品卷":""}}</view>
							<view class="tui-coupon-title">{{item.useType==0?"全部商品可用":item.useType==1?"同类商品可用":item.useType==2?"只该商品可用":""}}</view>
						</view>
						<view class="tui-coupon-rule">
							<view class="tui-rule-box tui-padding-btm">
								<view class="tui-coupon-circle"></view>
								<view class="tui-coupon-text">不可叠加使用</view>
							</view>
							<view class="tui-rule-box">
								<view class="tui-coupon-circle"></view>
								<view class="tui-coupon-text">{{item.startTime|formatDates}}至{{item.endTime|formatDates}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="tui-btn-box" v-if="index==0">
					<tui-button  type="danger" width="152rpx" height="52rpx" :size="24" shape="circle" :plain="true">立即使用</tui-button>
				</view>
			</view>
			
		</view>
		<u-empty v-if="list.length==0" mode="coupon" margin-top="200"></u-empty>
		<!--加载loadding-->
		<tui-loadmore v-if="loadding&&list.length!=0" :index="3" type="red"></tui-loadmore>
		<tui-nomore v-if="!pullUpOn&&list.length!=0" backgroundColor="#f5f5f5"></tui-nomore>
		<!--加载loadding-->
		
		<u-no-network tips="哎呀，网络信号丢失"></u-no-network>
		<failTimeout v-show="failTimeout"></failTimeout>
	</view>
</template>

<script>
	import UmsMemberCouponController from '../api/UmsMemberCouponController.js'
	import {formatDate} from "../utils/date.js"
	export default {
		data() {
			return {
				loadding: false,
				pullUpOn: true,
				productId:null,
				list:[],
				failTimeout: false,
				pages:0,
			}
		},
		props:["index"],
		created() {
			this.lists()
		},
		methods: {
			lists(){
				
				if(this.pullUpOn){
					this.loadding=true
					UmsMemberCouponController.list(this.index,this.pages,6).then(res=>{
						if(res.data.code==200){
							res.data.data.map(e=>{
								this.list.push(e)
							})
							
							if(res.data.data.length==0||res.data.data.length!=6){
								
								this.pullUpOn=false;
							}
							this.loadding=false
							this.pages+=6;
							
						}
					}).catch(err=>{
						console.log(err)
					})
				}
				
			}
		},
		filters:{
			formatDates(date){	
				return formatDate(new Date(date),"yyyy-MM-dd");
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.pullUpOn = true
				uni.stopPullDownRefresh()
			}, 200);
		},
		onReachBottom() {
			//只是测试效果，逻辑以实际数据为准
			if (!this.pullUpOn) return;
			this.loadding = true
			setTimeout(() => {
				this.loadding = false
				this.pullUpOn = false
			}, 1000)
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}
</style>
<style scoped>
	
	
	.container {
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-coupon-list {
		width: 100%;
		padding: 0 25rpx;
		box-sizing: border-box;
	}

	.tui-coupon-banner {
		width: 100%;
	}

	.tui-coupon-item {
		width: 100%;
		height: 210rpx;
		position: relative;
		display: flex;
		align-items: center;
		padding-right: 30rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	.tui-coupon-bg {
		width: 100%;
		height: 210rpx;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 1;
	}

	.tui-coupon-sign {
		height: 110rpx;
		width: 110rpx;
		position: absolute;
		z-index: 9;
		top: -30rpx;
		right: 40rpx;
	}

	.tui-coupon-item-left {
		width: 218rpx;
		height: 210rpx;
		position: relative;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		flex-shrink: 0;
	}

	.tui-coupon-price-box {
		display: flex;
		color: #e41f19;
		align-items: flex-end;
	}

	.tui-coupon-price-sign {
		font-size: 30rpx;
	}

	.tui-coupon-price {
		font-size: 70rpx;
		line-height: 68rpx;
		font-weight: bold;
	}

	.tui-price-small {
		font-size: 58rpx !important;
		line-height: 56rpx !important;
	}


	.tui-coupon-intro {
		background: #F7F7F7;
		padding: 8rpx 10rpx;
		font-size: 26rpx;
		line-height: 26rpx;
		font-weight: 400;
		color: #666;
		margin-top: 18rpx;
	}

	.tui-coupon-item-right {
		flex: 1;
		height: 210rpx;
		position: relative;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 24rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	.tui-coupon-content {
		width: 82%;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.tui-coupon-title-box {
		display: flex;
		align-items: center;
	}

	.tui-coupon-btn {
		padding: 6rpx;
		background: #FFEBEB;
		color: #e41f19;
		font-size: 25rpx;
		line-height: 25rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		transform: scale(0.9);
		transform-origin: 0 center;
		border-radius: 4rpx;
		flex-shrink: 0;
	}

	.tui-color-grey {
		color: #888 !important;
	}

	.tui-bg-grey {
		background: #F0F0F0 !important;
		color: #888 !important;
	}

	.tui-coupon-title {
		width: 100%;
		font-size: 26rpx;
		color: #333;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.tui-coupon-rule {
		padding-top: 52rpx;
	}

	.tui-rule-box {
		display: flex;
		align-items: center;
		transform: scale(0.8);
		transform-origin: 0 100%;
	}

	.tui-padding-btm {
		padding-bottom: 6rpx;
	}

	.tui-coupon-circle {
		width: 8rpx;
		height: 8rpx;
		background: rgb(160, 160, 160);
		border-radius: 50%;
	}

	.tui-coupon-text {
		font-size: 28rpx;
		line-height: 28rpx;
		font-weight: 400;
		color: #666;
		padding-left: 8rpx;
		white-space: nowrap;
	}

	.tui-top20 {
		margin-top: 20rpx;
	}

	.tui-coupon-title {
		font-size: 28rpx;
		line-height: 28rpx;
	}


	.tui-coupon-radio {
		transform: scale(0.7);
		transform-origin: 100% center;
	}

	.tui-btn-box {
		position: absolute;
		width: 146rpx;
		height: 52rpx;
		right: 20rpx;
		bottom: 40rpx;
		z-index: 10;
	}

	/* #ifdef APP-PLUS || MP */
	.wx-radio-input {
		margin-right: 0 !important;
	}

	/* #endif */

	/* #ifdef H5 */
	>>>uni-radio .uni-radio-input {
		margin-right: 0 !important;
	}

	/* #endif */
</style>
